package com.bwie.activity.controller;

import com.bwie.activity.service.ActivityService;
import com.bwie.activity.utils.OssUtil;
import com.bwie.common.pojo.req.*;
import com.bwie.common.pojo.res.ActivityRes;
import com.bwie.common.pojo.res.PrizeRes;
import com.bwie.common.pojo.res.RuleRes;
import com.bwie.common.result.PageResult;
import com.bwie.common.result.Result;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.validation.constraints.NotNull;
import java.util.List;

@RestController
@RequiredArgsConstructor
public class ActivityController {
    private final ActivityService activityService;
    private final OssUtil ossUtil;

    /**
     * 获取活动列表
     * @param activityReq
     * @return
     */
    @PostMapping("/activityList")
    public Result<PageResult<ActivityRes>> activityList(@RequestBody ActivityReq activityReq){
        return Result.success(activityService.activityList(activityReq));
    }

    /**
     * 获取奖品规则列表
     * @return
     */
    @PostMapping("/getPrizeRules")
    public Result<List<RuleRes>> getPrizeRules(@RequestBody EditNpReq editNpReq){
        List<RuleRes> list = activityService.getPrizeRules(editNpReq);
        return Result.success(list);
    }

    /**
     * 修改规则
     * @param updateRuleReq
     * @return
     */
    @PutMapping("/updateRule")
    public Result<Void> updateRule(@Validated @RequestBody UpdateRuleReq updateRuleReq){
        activityService.updateRule(updateRuleReq);
        return Result.success();
    }

    /**
     * 获取抽奖类型下拉框
     * @return
     */
    @GetMapping("/getActivity")
    public Result<List<ActivityRes>> getActivity(){
        List<ActivityRes> list = activityService.getActivity();
        return Result.success(list);
    }

    /**
     * 获取抽奖类型下拉框
     * @return
     */
    @GetMapping("/getRule")
    public Result<List<RuleRes>> getRule(){
        List<RuleRes> list = activityService.getRule();
        return Result.success(list);
    }

    /**
     * 上传图片
     * @param file
     * @return
     */
    @PostMapping("/upload")
    public Result<String> upload(MultipartFile file){
        String path = ossUtil.uploadMultipartFile(file);
        return Result.success(path);
    }

    /**
     * 添加活动
     * @param activityAddReq
     * @return
     */
    @PostMapping("/addActivity")
    public Result<Void> addActivity(@Validated @RequestBody ActivityAddReq activityAddReq){
        activityService.addActivity(activityAddReq);
        return Result.success();
    }

    /**
     * 获取奖品信息
     * @param prizeReq
     * @return
     */
    @PostMapping("/getRuleByUserId")
    public Result<List<PrizeRes>> getRuleByUserIdId(@Validated @RequestBody PrizeReq prizeReq){
        List<PrizeRes> list = activityService.getRuleByUserIdId(prizeReq);
        return Result.success(list);
    }

    /**
     * 添加抽奖记录
     * @param lotteryLogReq
     * @return
     */
    @PostMapping("/addLotteryLog")
    public Result<Void> addLotteryLog(@RequestBody LotteryLogReq lotteryLogReq){
        activityService.addLotteryLog(lotteryLogReq);
        return Result.success();
    }
}
